<?php
if(cmd('setlevel',50)){
	$userLevelMod=strtolower($msg_args[1]);
	$levelLevelMod=(int)$msg_args[2];
	$levels[$userLevelMod]=$levelLevelMod;
	reply($msg_args[1].' now has an access level of '.$levels[$userLevelMod]);
	updateAccess();
}
if(cmd('ignore',50)){
	$userLevelMod=strtolower($msg_args[1]);
	$oldlevels[$userLevelMod] = 0;
	if (array_key_exists($userLevelMod, $levels))
		$oldlevels[$userLevelMod] = intval($levels[$userLevelMod]);
	$levels[$userLevelMod] = -1;
	reply($msg_args[1].' has been ignored [access level -1]');
	updateAccess();
}

if(cmd('unignore',50)){
	$userLevelMod=strtolower($msg_args[1]);
	$levels[$userLevelMod]=$oldlevels[$userLevelMod];
	reply($msg_args[1].' now has an access level of '.$levels[$userLevelMod]);
	updateAccess();
}

if(cmd('level')){
	$userLevel=strtolower($msg_args[1]);
	if(empty($userLevel)){
		$userLevel=strtolower($source_nick);
		if(!$levels[$userLevel]){
			$userLevel=strtolower($source_host);
		}
		echo $userLevel;
		if($levels[$userLevel]){
			reply('your access level is '.$levels[$userLevel]);
		} else {
			reply('your access level hasn\'t been set, so it defaults to 0');
		}
	} else {
		if($levels[$userLevel]){
			reply($msg_args[1].'\'s access level is '.$levels[$userLevel]);
		} else {
			reply($msg_args[1].'\'s access level hasn\'t been set, so it defaults to 0');
		}
	}
}

if(cmd('levels')){
	$levelStr="";
	foreach($levels as $user=>$level){
		if ($level != 0)
			$levelStr.="$user: $level, ";
	}
	$levelStr=trim($levelStr,", ");
	if(empty($levelStr))
		$levelStr='No set access levels... This shouldn\'t happen people...';
	reply($levelStr);

}
?>